<?php
require_once 'WxFunction.php';

if ( !isset($_GET['sign']) || !isset($_GET['get']) || !isset($_GET['ts'])){
    WxFunction::ajaxReturn(NULL, '非法请求', 1);
}

require_once 'WxConfig.php';
require_once 'WxApi.php';
require_once 'WxAes.php';
WxAes::$_key = WxConfig::KEY;

// 校验签名
if (WxFunction::verify($_GET['sign'])){
    switch ($_GET['get']){
        case 'access_token':
            $error_msg = '获取AccessToken失败';
            $result = WxApi::getAccessToken();
            break;
        case 'api_ticket':
            $error_msg = '获取JsApiTicket失败';
            $result = WxApi::getJsApiTicket();
            break;
        case 'card_ticket':
            $error_msg = '获取CardTicket失败';
            $result = WxApi::getCardTicket();
            break;
        default:
            WxFunction::ajaxReturn(NULL, '无效的Action:' . $_GET['get'], 1);
    }

    if ($result !== FALSE){
        WxFunction::ajaxReturn($result);
    } else {
        WxFunction::ajaxReturn(NULL, $error_msg);
    }
} else {
    WxFunction::ajaxReturn(NULL, '签名校验失败', 1);
}